Skip to content

perf(agc): sort guest buffer regions through indices before merging them - #4248

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
hypermoist:perf/guest-buffer-region-index-sort
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
hypermoist:perf/guest-buffer-region-index-sort

Conversation

@hypermoist

Copy link
Copy Markdown
Contributor

What

GuestBufferMemory::UploadPrepare sorted the build's Region objects themselves by address, then appended them to a merged vector that was never reserved. A Region holds several vectors and shared pointers (a few hundred bytes), so each resource build moved every region many times through the sort and the reallocations; on Killing Floor 3 (PPSA08427) the sort fell back to its heap phase and UploadPrepare was about a sixth of the queue-0 worker at the title screen.

The regions are now sorted through an index array and merged is reserved up front, so each region is moved once. The order and the merge are the same: equal begin addresses were unordered before and still are.

Tested

Linux (CachyOS, kernel 7.2.9), RTX 3060 (NVIDIA 615.78.08), GCC 16.2.1, Release.

  • Killing Floor 3 (PPSA08427, 02.011.000), on our fork with the same settings before and after, measured with perf on the queue-0 worker at the title screen: UploadPrepare went from 17.4% to 8.8% of its samples, and the title screen from about 26 to 28 presents per 10 s. Measured on a branch based on main from 2026-10-11; UploadPrepare's sort and merge are unchanged on current main. The title does not run on main alone (it stops at a draw with clip distances, feat(agc): vertex clip and cull distances #423).
  • On this branch: agc_driver_graphics, agc_driver_dcc_keys_first_write and agc_driver_storage_cache_budget pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo

UploadPrepare sorted the build's Region objects themselves, each a few
hundred bytes of vectors and shared pointers, and grew the merged list
without reserving it, moving every region many times per resource build.
Sorting an index array and reserving the merged list moves each region
once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uzy15wqYTt6iWyxYXEzUWo
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1345 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L2760-2763

@Scramblrrrr

Copy link
Copy Markdown
Contributor

Preparing a007 Windows cross-test of your existing commit8083dd11149, author retained, applied cleanly on our experimental runtime-table integration: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-region-sort-cross-test head908ee2bc431dfa78070e36e01044460e3fcba7e5. Not built or staged yet. After the ongoing range-map baseline, will run graphics/DCC/storage/sparse-buffer native checks and the same warm-cache007 configuration. No competing implementation or current-main mergeability claim. AI-assisted: Codex.

@Scramblrrrr

Copy link
Copy Markdown
Contributor

Native Windows cross-test on 908ee2b passed 5/5 in 6.27 s: graphics, DCC keys first write, storage cache budget, driver sparse-buffer holes, and graphics sparse-buffer holes. RTX 5070 Ti, Vulkan required, no skips. This includes our existing sparse-copy/range-map integration; not a current-main-only claim.

No isolated 007 FPS result for this change yet. The preceding game run (without the sorting change staged) progressed beyond the licence screen and then hit the known #423 clip-distance export stop, so that integration is next before the next game run. Your change remains author-preserved and no competing PR is proposed.

AI-assisted: Codex.

@Scramblrrrr

Copy link
Copy Markdown
Contributor

Re-cross-test on the newer 007 recovery/fiber/key-reservation stack: your exact8083dd11149 author-preserved, integration e8cc22c (https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-key-and-region-sort), one production file changed relative to163f0b856. Windows/RTX5070Ti/GCC15.2 Release: full mocked agc_driver_graphics PASS5.52s; native agc_driver_dcc_keys_first_write PASS0.59s and agc_driver_storage_cache_budget PASS0.39s, neither skipped. The latter two initially were not built; after building them, both pass. Clean diff-check. This is the experimental integration, not current-main-only validation.

Game comparison has started normal warm-cache/cache16, graphicsFFD11FE14B53708C49F639F3826E31B6CC4CE6BD55AB267CFE07CAE3464C69DD/libc99D37E34. No sampler/profile or concurrent builds/native tests. Prior key-only run163f intentionally ended after~4m37 Resume, slow scene0.24->0.16FPS, unsupported image-table writes/partial output persist; no sorting FPS result yet. AI-assisted: Codex.

@Scramblrrrr

Copy link
Copy Markdown
Contributor

007 comparison on e8cc22c (#4248 on key/recovery/fiber stack) ended intentionally22:07:56.753UTC (4m23 after Resume22:03:34.078), not a crash. GraphicsFFD11FE1/libc99D37E34/cache16, normal warm cache, no sampler/profile or concurrent builds/native tests. Startup2FPS; slow scene0.43 then0.22->0.15FPS, same bright circles over black. Last private22.766GB/free5.312GB. Image-table deferred write-backs remain unsupported. This single Windows run does not establish a title-level sorting improvement; its native tests pass as reported above.

Also found #4206 absent from this current recovery stack, though it was cross-tested on our earlier8c1ed096 stack. Prepared author-preserved fixture/fix port a9454c2 (codex/first-light-key-sort-sparse-holes), not staged. CPU hole/native GPU readback/full mocked graphics pass3/3 in6.01s; verifying production-only negative control next. This fixes recycled sparse-hole bytes, not a claimed cause of the missing scene. Still leaving runtime-table stores/reference-texture fix to SleglJan. AI-assisted: Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants